package com.ruoyi.applet.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.ruoyi.applet.service.IOverdueRecordInfoService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.OverdueRecordInfoMapper;
import com.ruoyi.db.domain.OverdueRecordInfo;

/**
 * 律所Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-23
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class OverdueRecordInfoServiceImpl implements IOverdueRecordInfoService
{
    @Autowired
    private OverdueRecordInfoMapper overdueRecordInfoMapper;

    /**
     * 查询律所
     * 
     * @param id 律所主键
     * @return 律所
     */
    @Override
    public OverdueRecordInfo selectOverdueRecordInfoById(Long id)
    {
        return overdueRecordInfoMapper.selectOverdueRecordInfoById(id);
    }

    /**
     * 查询律所列表
     * 
     * @param overdueRecordInfo 律所
     * @return 律所
     */
    @Override
    public List<OverdueRecordInfo> selectOverdueRecordInfoList(OverdueRecordInfo overdueRecordInfo)
    {
        return overdueRecordInfoMapper.selectOverdueRecordInfoList(overdueRecordInfo);
    }

    /**
     * 查询律所列表
     *
     * @param overdueRecordInfo 律所
     * @return 律所
     */
    @Override
    public List<Map<String, Object>> selectOverdueRecordInfoMapList(OverdueRecordInfo overdueRecordInfo)
    {
        List<Map<String, Object>> maps = overdueRecordInfoMapper.selectOverdueRecordInfoMapList(overdueRecordInfo);
        // 过滤出status==1的对象
        if (maps != null && !maps.isEmpty()) {
            List<Map<String, Object>> filteredMaps = new ArrayList<>();
            for (Map<String, Object> map : maps) {
                Object statusObj = map.get("status");
                if (statusObj instanceof Integer && (Integer) statusObj == 1) {
                    filteredMaps.add(map);
                }
            }
            return filteredMaps;
        }

        return Collections.emptyList();
    }

    /**
     * 新增律所
     * 
     * @param overdueRecordInfo 律所
     * @return 结果
     */
    @Override
    public int insertOverdueRecordInfo(OverdueRecordInfo overdueRecordInfo)
    {
        overdueRecordInfo.setCreateTime(DateUtils.getNowDate());
        return overdueRecordInfoMapper.insertOverdueRecordInfo(overdueRecordInfo);
    }

    /**
     * 修改律所
     * 
     * @param overdueRecordInfo 律所
     * @return 结果
     */
    @Override
    public int updateOverdueRecordInfo(OverdueRecordInfo overdueRecordInfo)
    {
        overdueRecordInfo.setUpdateTime(DateUtils.getNowDate());
        return overdueRecordInfoMapper.updateOverdueRecordInfo(overdueRecordInfo);
    }

    /**
     * 批量删除律所
     * 
     * @param ids 需要删除的律所主键
     * @return 结果
     */
    @Override
    public int deleteOverdueRecordInfoByIds(Long[] ids)
    {
        return overdueRecordInfoMapper.deleteOverdueRecordInfoByIds(ids);
    }

    /**
     * 删除律所信息
     * 
     * @param id 律所主键
     * @return 结果
     */
    @Override
    public int deleteOverdueRecordInfoById(Long id)
    {
        return overdueRecordInfoMapper.deleteOverdueRecordInfoById(id);
    }
}
